export function assExamImgUrls(data) {
  const { attr211, attr227 } = data
  // attr227 肺功能检查
  // attr211 过敏源检测
  const attr = []
  if (attr211) attr.push({ name: '过敏原检测', url: attr211 })
  if (attr227) attr.push({ name: '肺功能检查', url: attr227 })
  return attr
}
export function assExam(data) {
  const {
    attr201,
    attr202,
    attr203,
    attr204,
    attr205,
    attr206,
    FnNO,
    CaNO,
    attr207,
    attr208,
    attr209,

    vt,
    mlPerKg,
    typrefPerTe,
    vpefPerVe,

    attr212,
    attr213,
    attr214,
    attr215,
    attr216,
    attr217,
    attr218,
    attr219,
    attr220,
    attr221,
    attr222,
    attr223,
    attr224,
    attr225,
    attr226,
    attr523,
    attr524,
    attr525,
    attr526,
  } = data

  let str = '肺功能检查内容：'
  if (attr201 || attr523) {
    str += ` 用力肺活量(FVC)`
    if (attr201) str += `最佳值 ${attr201}`
    str += attr201 && !attr523 ? `。` : '，'
    if (attr523) str += `最佳值百分比(%) ${attr523}%。`
  }
  if (attr202 || attr524) {
    str += ` 一秒量(FEV1)`
    if (attr202) str += `最佳值 ${attr202}，`
    str += attr202 && !attr524 ? `。` : '，'
    if (attr524) str += `最佳值百分比(%) ${attr524}%。`
  }
  if (attr203 || attr525) {
    str += ` 一秒率(FEV1/FVC)`
    if (attr203) str += `最佳值 ${attr203}，`
    str += attr203 && !attr525 ? `。` : '，'
    if (attr525) str += `最佳值百分比(%) ${attr525}%。`
  }
  if (attr204 || attr526) {
    str += ` 最大呼气中期流量(MMEF75/25)`
    if (attr204) str += `最佳值 ${attr204}，`
    str += attr204 && !attr526 ? `。` : '，'
    if (attr526) str += `最佳值百分比(%) ${attr526}%。`
  }

  if (attr205) str += `一氧化氮(FeNO)：${attr205}ppb，`
  // 保留原有的属性
  if (attr206) str += `一氧化氮(nNO)：${attr206}ppb，`
  if (FnNO) str += `一氧化氮(FnNO)：${FnNO}ppb，`
  if (CaNO) str += `一氧化氮(CaNO)：${CaNO}ppb，`

  if (attr207) str += `血清IgE：${attr207}IU/ml，`
  if (attr208) str += `，外周血嗜酸性粒细胞比例：${attr208}%`
  if (str !== '肺功能检查内容：') str += '。'

  if (attr209) str += `其它检验结果: ${attr209}。`

  if (vt || mlPerKg || typrefPerTe || vpefPerVe)
    str += vtMlTyprefVpefToString(vt, mlPerKg, typrefPerTe, vpefPerVe)

  str += attr212to220(
    attr212,
    attr213,
    attr214,
    attr215,
    attr216,
    attr217,
    attr218,
    attr219,
    attr220
  )
  str += attr221to226(attr221, attr222, attr223, attr224, attr225, attr226)
  if (str === '肺功能检查内容：') return ''
  return str
}

/**
 *
 * @param {*} vt
 * @param {*} mlPerKg
 * @param {*} typrefPerTe
 * @param {*} vpefPerVe
 * @returns
 */
function vtMlTyprefVpefToString(vt, mlPerKg, typrefPerTe, vpefPerVe) {
  let str = []
  if (vt) str.push(`潮气呼吸功能检查潮气值(VT): ${vt}ml`)
  if (mlPerKg) str.push(`公斤体重潮气量: ${mlPerKg}ml/kg`)
  if (typrefPerTe) str.push(`达峰时间比(TPTEF/TE): ${typrefPerTe}%`)
  if (vpefPerVe) str.push(`达峰容积比(VPEF/VE): ${vpefPerVe}%`)

  return str.join('，') + '。'
}

// attr210 过敏原判断 attr211 过敏原检测图片
// attr227 肺功能检查
function attr212to220(
  attr212,
  attr213,
  attr214,
  attr215,
  attr216,
  attr217,
  attr218,
  attr219,
  attr220
) {
  // 鸡蛋,鱼虾,尘螨,花粉,其他,牛奶
  let str = ''
  if (attr212 && attr212.includes('牛奶')) str += valueTotal('牛奶', attr213)
  if (attr212 && attr212.includes('鸡蛋')) str += valueTotal('鸡蛋', attr214)
  if (attr212 && attr212.includes('鱼虾')) str += valueTotal('鱼虾', attr215)
  if (attr212 && attr212.includes('花粉')) str += valueTotal('花粉', attr219)
  if (attr216) {
    str += '尘螨，'
    if (attr216.includes('屋尘螨')) str += valueTotal('屋尘螨', attr217)
    if (attr216.includes('粉尘螨')) str += valueTotal('粉尘螨', attr218)
  }
  if (str) str = '过敏原检测：' + str
  if (attr212 && attr212.includes('其他')) str += valueTotal('其他：', attr220)
  return str
}

function attr221to226(attr221, attr222, attr223, attr224, attr225, attr226) {
  let str = ''
  if (attr221) str += `支气管激发试验：${attr221}，`
  if (attr222) str += `支气管舒张试验：${attr222}，`
  if (attr223) str += `呼气峰流速(PEF)两周波动率：${attr223}%，`
  if (attr224) str += `ICS和/或白三烯调节剂治疗4-12周FEV1改善率：${attr224}%，`
  if (attr225 && attr226)
    str += `PEF占正常值或本人最佳值的百分数：SABA治疗前${attr225}%，SABA治疗后${attr226}%。`
  if (attr225 && !attr226)
    str += `PEF占正常值或本人最佳值的百分数：SABA治疗前${attr225}%。`
  if (!attr225 && attr226)
    str += `PEF占正常值或本人最佳值的百分数：SABA治疗后${attr226}%。`
  return str
}
function valueTotal(head, body, foot = 'IU/ml，') {
  if (head && body) {
    return `${head}：${body}${foot}`
  } else if (head) {
    return `${head}`
  }
  return ''
}
